package com.koron.housing.statistics.service.impl;

import com.github.pagehelper.PageInfo;
import com.koron.bean.query.PageQuery;
import com.koron.housing.contract.bean.param.HousingContractBillParam;
import com.koron.housing.contract.bean.vo.HousingContractStatistics;
import com.koron.housing.contract.mapper.HousingContractMapper;
import com.koron.housing.info.bean.query.HousingInfoStatisticsQuery;
import com.koron.housing.info.bean.vo.HousingInfoStatistics;
import com.koron.housing.info.mapper.HousingInfoMapper;
import com.koron.housing.staff.bean.query.HousingStaffStatisticsQuery;
import com.koron.housing.staff.bean.vo.HousingStaffStatistics;
import com.koron.housing.staff.mapper.HousingStaffMapper;
import com.koron.housing.statistics.service.HousingStatisticsService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

/**
 * @author jzp
 * @since 2022/3/10
 */
@Service("statisticsService")
public class HousingStatisticsServiceImpl implements HousingStatisticsService {

    /**
     * 租赁统计
     */
    @Override
    @TaskAnnotation("listLease")
    public List<HousingStaffStatistics> listLease(SessionFactory factory, HousingStaffStatisticsQuery query) {
        HousingStaffMapper mapper = factory.getMapper(HousingStaffMapper.class);
        return mapper.selectStatisticsList(query);
    }

    @Override
    @TaskAnnotation("pageLease")
    public PageInfo<HousingStaffStatistics> pageLease(SessionFactory factory, PageQuery pageQuery, HousingStaffStatisticsQuery query) {
        return HousingStatisticsService.super.pageLease(factory, pageQuery, query);
    }

    /**
     * 房源统计
     */
    @Override
    @TaskAnnotation("listInfo")
    public List<HousingInfoStatistics> listInfo(SessionFactory factory, HousingInfoStatisticsQuery query) {
        HousingInfoMapper mapper = factory.getMapper(HousingInfoMapper.class);
        return mapper.selectGroupInfo(query);
    }

    /**
     * 发票统计
     */
    @Override
    @TaskAnnotation("listBill")
    public List<HousingContractStatistics> listBill(SessionFactory factory, HousingContractBillParam query) {
        HousingContractMapper mapper = factory.getMapper(HousingContractMapper.class);
        Assert.notNull(query.getYear(), "年份条件不能为空");
        return mapper.selectStatisticsList(query);
    }
}
